import { Component, OnInit } from '@angular/core';
import { MerchantwineService } from 'src/app/service/merchantwine.service';
import { ActivatedRoute } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd';
import { CommonService } from 'src/app/service/common.service';
@Component({
  selector: 'app-settlementrecords',
  templateUrl: './agentmerchantwine.component.html',
  styleUrls: ['./agentmerchantwine.component.scss'],
  providers: [MerchantwineService]
})
export class AgentmerchantwineComponent implements OnInit {
  mid: any;
  pageIndex = 1;
  pageSize = 15;
  total = 1;
  doc: any = {};
  dataSet = [];
  loading = true;
  isOkLoading = false;
  addisVisible = false;
  statuslist: Array<any> = [];

  constructor(private msg: NzMessageService, private ar: ActivatedRoute,
    private merchantwineService: MerchantwineService, private commonservice: CommonService) {
    this.mid = this.ar.snapshot.params.id;
  }
  ngOnInit() {
    this.searchData();
  }
  searchData(reset: boolean = false): void {
    this.loading = true;
    this.merchantwineService.querybymid({
      offset: this.pageIndex,
      limit: this.pageSize,
      mid: this.mid
    }).then((res) => {
      this.loading = false;
      this.total = res.total
      this.dataSet = res.rows;
    });
  }
  edit(id: any) {
    this.addisVisible = true;
    this.merchantwineService.queryById(id).then((r) => {
      this.doc = r;
    });
  }
  lock(id: any) {
    this.commonservice.confirm('下架后餐厅将不再供应此酒饮！确认下架吗？', () => {
      this.merchantwineService.lock(id).then((res) => {
        this.commonservice.alert('下架成功');
        this.searchData();
      });
    });
  }
  open(id: any) {
    this.commonservice.confirm('上架后餐厅将开始供应此酒饮！确认上架吗？', () => {
      this.merchantwineService.open(id).then((res) => {
        this.commonservice.alert('上架成功');
        this.searchData();
      });
    });
  }

  handleCancel() {
    this.addisVisible = false;
    this.doc = {}
  }

  handleOk() {
      this.merchantwineService.agentupdatwinesstock(
        { _id: this.doc._id, stock: this.doc.stock }).then((r) => {
          this.addisVisible = false;
          this.msg.info('更新库存成功');
          this.searchData();
        });
  }
}
